/*
    Copyright 2010 Nathaniel Fairfield <than@timbrel.org>

    This file is part of Ravec.

    Ravec is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Ravec is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Ravec.  If not, see <http://www.gnu.org/licenses/>.
*/

// The ArrayGrid implements a uniform array-based 3D map.

#ifndef _RAVEC_ARRAY_GRID_H_
#define _RAVEC_ARRAY_GRID_H_

#include "b3d_grid.h"
#include <limits>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>

namespace ravec {

template<typename T>
class ArrayGrid : public B3DGrid<T> {
 public:
  ArrayGrid(int size_x, int size_y, int size_z, T initial_value)
    : B3DGrid<T>(size_x, size_y, size_z, initial_value) {
    data_ = new T[size_x * size_y * size_z];
    // Set initial value.
    for (int i = 0; i < size_x * size_y * size_z; ++i) {
      data_[i] = initial_value;
    }
  }

  virtual ~ArrayGrid() {
    delete[] data_;
  }

  // Basic accessors.
  virtual T Get(int x, int y, int z) const {
    return data_[((x * Grid<T>::size_y_) + y) * Grid<T>::size_z_ + z];
  }
  virtual T Set(int x, int y, int z, T value) {
    return data_[((x * Grid<T>::size_y_) + y) * Grid<T>::size_z_ + z] = value;
  }

 protected:
  // Array that stores the grid cell values.
  T *data_;
};

}  // namespace ravec

#endif  // _RAVEC_ARRAY_GRID_H_
